// pages/remark/remark.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //图标
    iconPath: app.globalData.iconPath,
    //访问java后台
    goJavaBackstagePath: app.globalData.goJavaBackstagePath,
    //测试数据图片
    testDataImgPath: app.globalData.testDataImgPath,

    product:{},    
    remarkPopup:false,
    presentPhoto:{},
    presentPhotoIndex:-1,
    orderId:null,

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var orderId = options.orderId;
    var productId = options.productId;
    this.setData({
      orderId:orderId,      
    });
    //发送请求到后台 获取验片页面数据
    // wx.request({
    //   url: this.data.goJavaBackstagePath+'/product/getProdcutPhotosRemark',
    //   data:{orderId:this.data.orderId,productId:productId},
    //   header: {
    //     'content-type': 'application/json'
    //   },
    //   success: function (res) {
    //     console.log(res.data)
    //   }
    // })
    this.setData({
      
      product: {
        'id': 22, 'orderProductCount': 6, 'productCount': 6, 'oneProductCount': 5, 'name': '实木相框挂墙16寸', 'url': this.data.iconPath+'/sellerportrait.png', 'photos': [
          { id: 1, productPhoto_id: 1, url: this.data.testDataImgPath+ '/mei1.jpg',remark:'' },
          { id: 2, productPhoto_id: 2, url: this.data.testDataImgPath+ '/mei2.jpg', remark: '' },
          { id: 3, productPhoto_id: 3, url: this.data.testDataImgPath+ '/mei3.jpg', remark: '' },
          { id: 4, productPhoto_id: 4, url: this.data.testDataImgPath+ '/mei4.jpg', remark: '' },
          { id: 5, productPhoto_id: 5, url: this.data.testDataImgPath+ '/mei5.jpg', remark: '' },
          { id: 6, productPhoto_id: 6, url: this.data.testDataImgPath+ '/mei6.jpg', remark: '' },
          { id: 7, productPhoto_id: 7, url: this.data.testDataImgPath+ '/mei7.jpg', remark: '' },
          { id: 8, productPhoto_id: 8, url: this.data.testDataImgPath+ '/mei8.jpg', remark: '' },
          { id: 9, productPhoto_id: 9, url: this.data.testDataImgPath+ '/mei9.jpg', remark: '' },
          { id: 10, productPhoto_id:10, url: this.data.testDataImgPath+ '/mei10.jpg', remark: '' },
          { id: 11, productPhoto_id: 11, url: this.data.testDataImgPath+ '/mei11.jpg', remark: '' },
          { id: 12, productPhoto_id: 12, url: this.data.testDataImgPath+ '/mei12.jpg', remark: '' },
          { id: 13, productPhoto_id: 13, url: this.data.testDataImgPath+ '/mei13.jpg', remark: '' },
          { id: 14, productPhoto_id: 14, url: this.data.testDataImgPath+ '/mei14.jpg', remark: '' },
          { id: 15, productPhoto_id: 15, url: this.data.testDataImgPath+ '/mei15.jpg', remark: '' },
          { id: 16, productPhoto_id: 16, url: this.data.testDataImgPath+ '/mei16.jpg', remark: '' },
        ]
       }
    });
  },
  openRemarkPopup:function(event){
    var productphotoid = event.target.dataset.productphotoid;
    for(var i=0;i<this.data.product.photos.length;i++){
      if (productphotoid == this.data.product.photos[i].productPhoto_id){
        this.data.presentPhotoIndex = i;
        break;
      }
    }
    this.setData({
      remarkPopup:true,
      presentPhoto: this.data.product.photos[this.data.presentPhotoIndex],
    });
  },
  closeRemarkPopup:function(){
    this.setData({
      remarkPopup: false,
    });
  },
  donotClosePopup:function(){},
  confirmRemark:function(event){
    this.data.product.photos[this.data.presentPhotoIndex].remark = event.detail.value.remarkContent;
    // wx.request({
    //   url: this.data.goJavaBackstagePath+'/customer/photo/photoRemark.do',
    //   data:{productPhotoId:this.data.product.photos[this.data.presentPhotoIndex].productPhoto_id,remark:this.data.product.photos[this.data.presentPhotoIndex].remark},
    //   header: {
    //     'content-type': 'application/json'
    //   },
    //   success: function (res) {
    //     console.log(res.data)
    //   }
    // })
    this.setData({remarkPopup: false,
      presentPhoto: {},
      product: this.data.product,
      });
  },
  previewPhoto:function(event){
    var current = event.target.dataset.current;
    var urls=[];
    for(var i=0;i<this.data.product.photos.length;i++){
      urls.push(this.data.product.photos[i].url);
    }
    wx.previewImage({ current,urls});
  },
  toOrder: function () {
    wx.redirectTo({ url: '/pages/order/order' })
  },
  toPhotoRepository: function () {
    wx.redirectTo({ url: '/pages/photoRepository/photoRepository' })
  },
})